package com.dream.keigezhushou.Activity.acty.personal;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.activity.BaseActivity;
import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyOrderActivity extends BaseActivity {

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.lv_all_order)
    ListView lvAllOrder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_order);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    //初始化界面
    protected void initView(){

        tvTitle.setText("全部订单");
    }

    //初始化数据
    protected void initData(){

        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //返回
                finish();
            }
        });

        //ListView创建适配器
        lvAllOrder.setAdapter(new OrderAdapter(this));
    }

    public class OrderAdapter extends BaseAdapter {

        private Context mContext;
        int c = 15;

        public OrderAdapter(Context context) {

            this.mContext = context;
        }

        @Override
        public int getCount() {
            return c;
        }

        @Override
        public Object getItem(int i) {
            return i;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            OrderHolder mHolder = null;
            if (view == null){

                view = LayoutInflater.from(mContext).inflate(R.layout.layout_order_item,null);
                mHolder = new OrderHolder();

                mHolder.tvStateKind = (TextView) view.findViewById(R.id.tv_state_kind);
                mHolder.tvStyle = (TextView) view.findViewById(R.id.tv_style);
                view.setTag(mHolder);

            }else {
                mHolder = (OrderHolder)view.getTag();
            }

            if (i % 2 == 0 ){
                mHolder.tvStateKind.setText("待消费");
                mHolder.tvStyle.setText("查看券码");
            }else if (i % 3 == 0){

                mHolder.tvStateKind.setText("待评价");
                mHolder.tvStyle.setText("评价");
            }else {
                mHolder.tvStateKind.setText("待付款");
                mHolder.tvStyle.setText("去付款");
            }
            return view;
        }

        class OrderHolder{

            TextView tvStateKind,tvStyle;

        }
    }
}
